package com.ljb.android.comm.router.interceptor

import android.content.Context
import android.os.Bundle
import com.ljb.android.comm.common.CommConstant
import com.ljb.android.comm.common.LocUser
import com.ljb.android.comm.router.core.IRouterInterceptor
import com.ljb.android.comm.router.core.RouterManager
import com.ljb.android.component.user.router.UserRouter

class LoginRouterInterceptor : IRouterInterceptor {

    override fun onIntercept(context: Context, path: String, bundle: Bundle): Boolean {
        val needLogin = bundle.getString(CommConstant.Key.KEY_INTERCEPTOR_LOGIN, "0")
        if (needLogin == "1") {
            // 需要检测是否是登录状态
            if (!LocUser.isLogIn()) {
                //未登录，进行拦截，并跳转至登录页
                val loginBundle = Bundle()
                loginBundle.putBundle(CommConstant.Key.KEY_LOGIN_TARGET , bundle)
                RouterManager.goActivity(context, UserRouter.Activity.USER_LOGIN, loginBundle)
                return true
            }
        }
        return false
    }
}